invoke async function as IIFE in example#958
invoke async function as IIFE in example#958avindra wants to merge 1 commit intotediousjs:masterfrom avindra:patch-1
Conversation
The example as listed currently does not run anything, so wrapping it up as an async IIFE.
|
Thanks for the contribution @avindra I'm not entirely sure this change makes the docs any more helpful - it's not intended to be a copy+paste example of getting a query to run, it's meant to be an abstract example of how you would go about writing code. I think putting the example code in an IIFE will actually make more people's code break as they'll copy+paste it into their functions and not understand why it's running when the function hasn't been called. |
It's been called in the IIFE! |
Yes, but is someone blindingly copy and pasting code going to understand that? these examples are not for blind copy and paste to get your application working, they are conceptual examples about how to make a request - if you can't figure out you need to actually call that code for it to run, I don't think they'll understand why it's running inside an IIFE |
|
If we do think this is how our docs should be written then every single example needs updating, right? |
|
Fair points, gents. I was able to get up and running from the example, so I'll leave it be for now. As you mentioned @dhensby everything else should get updated if this is the approach. I'm closing this for now... may re-open it later on if I get some time to update the rest of the docs |
|
I saw this recently too: https://levelup.gitconnected.com/why-its-time-to-stop-using-javascript-iifes-b62602f25bfc |
|
@dhensby good points are raised in that anti-iife article. Top level await is available (behind a flag) in node 14.3.0 and is already in deno. At some point the function can be removed, and the top level await should work as expected. |
The example as listed currently does not run anything, so wrapping it up as an async IIFE.
What this does:
Make sure users who are copy+pasting the example in the
READMEcan get it to run